#!/usr/bin/env python
# -*- conding: utf-8 -*-

"""
@Time     : 2024/8/22 13:32
@Author   : liujingmao
@File     : 3. Model流式输出.py
"""

import dotenv
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

dotenv.load_dotenv()

# 1.编排Prompt
prompt = ChatPromptTemplate.from_template("你能简单介绍下{subject}么?")

# 2.构建大语言模型
llm = ChatOpenAI(model="gpt-3.5-turbo-16k",temperature=0.8)

# 3.流式输出
response = llm.stream(prompt.invoke({"subject": "人工智能"}))
for chunk in response:
    print(chunk.content, flush=True, end="")
